/*
 * UserNet  --  TCP/IP implementation in userspace
 * Copyright (C) 2010  Robert Millan
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef UNET_DEV_H
#define UNET_DEV_H

#include <stdint.h>
#include <net/ethernet.h>	/* ETH_ALEN */
#include <netinet/in.h>		/* struct in_addr */

struct unet_device;

struct unet_datalink
{
  char name[64];
  void (*send_packet) (int type, const uint8_t mac_addr[ETH_ALEN], struct unet_device *device,
		       const uint8_t *packet, const uint32_t len);
  int (*get_mac) (struct in_addr ip_addr, uint8_t *mac_addr,struct unet_device *device);
};

struct unet_driver
{
  char name[64];
  void *this;
  struct unet_datalink datalink;
  void (*send_packet) (struct unet_device *device, const uint8_t *packet, const uint32_t len);
};

struct unet_device
{
  uint32_t id;
  struct unet_driver driver;
  uint8_t mac_addr[ETH_ALEN];
  struct in_addr ip_addr;
  struct unet_client **port_list;
  struct unet_device *next;
};

extern void unet_device_add (struct unet_device *device);
extern struct unet_device *unet_device_find (uint32_t id);
extern struct unet_device *unet_device_iterate (int (*hook) (struct unet_device *device));
extern int unet_device_count ();

#endif
